<?php

/**
 * 后台select选项通用函数
 * @param $list
 * @param string $id
 * @param string $name
 * @return array
 */
function createOptions($list, $id = 'id', $name = 'name')
{
    if (!is_object($list)) {
        return [];
    }

    $arr = [];
    foreach ($list as $v) {
        $arr[$v->$id] = $v->$name;
    }

    return $arr;
}

function create_order($id = 0, $type = 1)
{
    $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
    $uCode = array('K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T');
    $len = count($yCode);
    $yu = $id % $len;
    $ye = (intval(date('Y')) - 2014) % $len;
    $orderSn = $yCode[$ye] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%04d%02d', rand(1000, 9999), rand(0, 99)) . $uCode[$yu] . $type;
    return $orderSn;
}

function think_ucenter_md5($str, $key = 'ThinkUCenter')
{
    return '' === $str ? '' : md5(sha1($str) . $key);
}

function newPic($val)
{
    return 'https://winesh.oss-cn-beijing.aliyuncs.com/' . $val;
}

function get_full_img($img)
{
    if (strpos($img, 'http') === false) {
        $img = 'https://winesh.oss-cn-beijing.aliyuncs.com/' . $img;
    }

    return $img;
}
